import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart' ;
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mfkb/config/Config.dart';
import 'package:mfkb/pages/modules/CustomRoute.dart';
import 'package:mfkb/pages/web/WebViewPlugin.dart';
import 'package:mfkb/plugin/MyBehavior.dart';

class SchoolFunList extends StatefulWidget {
  List data ;

  SchoolFunList({Key key , @required this.data}):super(key:key) ;

  @override
  _SchoolFunListState createState() => _SchoolFunListState();
}

class _SchoolFunListState extends State<SchoolFunList> {
  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.dark ,
      child: Scaffold(
        body: Container(
          color:Color.fromARGB(255, 245, 246, 248) ,
          child: Column(
            children: <Widget>[
              Container(
                height: MediaQuery.of(context).padding.top ,
              ) ,
              Container(
                height: 45,
                child: Row(
                  children: <Widget>[
                    Container(
                      width: 17,
                      height: 17,
                      margin: EdgeInsets.only(left:ScreenUtil().setWidth(19)),
                      child: GestureDetector(
                        child: Container(
                          width: 17,
                          height: 17,
                          child: Image.asset("assets/images/back.png" , fit: BoxFit.fill,),
                        ),
                        onTap: (){
                          Navigator.of(context).pop() ;
                        },
                      ),
                    ) ,
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Text("更多功能" , style: TextStyle( 
                            color: Color.fromARGB(255, 19 , 28 , 53) , 
                            fontSize: ScreenUtil().setSp(18) , 
                            fontWeight: FontWeight.bold  
                          ),), 
                        ),
                      ),
                    ) ,
                    Container(
                      height: 17 ,
                      width: 36 ,
                      margin: EdgeInsets.only(right:ScreenUtil().setWidth(15)) ,
                    ) 
                  ],
                ),
              ) ,
              Expanded(
                child: ScrollConfiguration(
                  behavior: MyBehavior() ,
                  child: ListView(
                    padding: EdgeInsets.all(0),
                    children: <Widget>[
                      Container(
                        width: ScreenUtil().setWidth(220),
                        margin: EdgeInsets.only(left:ScreenUtil().setWidth(15) , right:ScreenUtil().setWidth(15) , top:ScreenUtil().setHeight(8)),
                        decoration: BoxDecoration(
                          color: Colors.white ,
                          borderRadius: BorderRadius.all(Radius.circular(8))
                        ),
                        child: Container(
                          margin: EdgeInsets.only(left:ScreenUtil().setWidth(18) , right:ScreenUtil().setWidth(18) , bottom:ScreenUtil().setHeight(23)),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Container(
                                height: ScreenUtil().setHeight(57),
                                child: Text("本校服务" , style: TextStyle(
                                  fontSize: ScreenUtil().setSp(18) ,
                                  color: Color.fromARGB(255, 19, 28, 53) ,
                                  fontWeight: FontWeight.normal ,
                                  height: ScreenUtil().setHeight(48) / ScreenUtil().setSp(18)
                                ),),
                              ) ,
                              Wrap(
                                spacing: ScreenUtil().setWidth(36),
                                runSpacing: ScreenUtil().setHeight(26),
                                children: List.generate(widget.data.length , (index){
                                  return GestureDetector(
                                    child: Container(
                                      width: ScreenUtil().setWidth(50),
                                      height: ScreenUtil().setHeight(58),
                                      child: Column(
                                        children: <Widget>[
                                          Container(
                                            width: ScreenUtil().setHeight(30),
                                            height: ScreenUtil().setHeight(30),
                                            child: widget.data[index]["type"] == "local" ? 
                                              Image.asset(widget.data[index]["icon"] , fit: BoxFit.fill,) : 
                                              CachedNetworkImage(imageUrl: Config().getImgHost() + widget.data[index]["icon"] ,) ,
                                          ) ,
                                          Container(
                                            margin: EdgeInsets.only(top:ScreenUtil().setHeight(10)),
                                            height: ScreenUtil().setHeight(17),
                                            child: Text(
                                              widget.data[index]["title"] , style: TextStyle(
                                                fontSize: ScreenUtil().setSp(12) ,
                                                color: Color.fromARGB(255, 19, 28, 53)
                                              ),overflow: TextOverflow.ellipsis,
                                            ),
                                          )
                                        ],
                                      ),
                                    ),
                                    onTap: (){
                                      if(widget.data[index]["type"] == "local"){ 
                                        if(widget.data[index]["url"] != null && widget.data[index]["url"] != ""){ 
                                          Navigator.of(context).pushNamed(widget.data[index]["url"]) ;
                                        }
                                      }else{
                                        Navigator.of(context).push(CustomRoute(WebViewPlugin(file:widget.data[index]["file"] , md5: widget.data[index]["md5"],type: 2,))) ;
                                      }
                                    },
                                  ) ;
                                }) ,
                              )
                            ],
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              )
            ]
          )
        )
      ),
    ) ;
  }
}